﻿Imports System.IO
Imports System.Web.Script.Serialization

Partial Public Class logonTmp
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim mode As String = Request.QueryString("mode")
        Dim txtFilePaht As String = Server.MapPath("login_tmp.txt")
        If mode = "write" Then
            Dim userName As String = Request.QueryString("userName")
            Dim pass As String = Request.QueryString("pass")

            Try
                Dim fileStream As New FileStream(txtFilePaht, FileMode.OpenOrCreate, FileAccess.ReadWrite)
                Dim steamWrite As New StreamWriter(fileStream)
                steamWrite.WriteLine(userName)
                steamWrite.WriteLine(pass)
                steamWrite.Close()
                fileStream.Close()
                Response.Write(userName)
            Catch ex As Exception
                Response.Write(ex.Message)
            End Try
        ElseIf (mode = "read") Then
            Try
                Dim read As String() = File.ReadAllLines(txtFilePaht)
                Dim logonInf As New LogonInfo()
                logonInf.User = read(0)
                logonInf.Pass = read(1)
                Dim js As New JavaScriptSerializer()
                Dim json As String = js.Serialize(logonInf)
                Response.Write(json)
            Catch ex As Exception
                Response.Write(ex.Message)
            End Try
        End If
    End Sub

End Class
Public Class LogonInfo
    Private _user As String
    Public Property User() As String
        Get
            Return _user
        End Get
        Set(ByVal value As String)
            _user = value
        End Set
    End Property

    Private _pass As String
    Public Property Pass() As String
        Get
            Return _pass
        End Get
        Set(ByVal value As String)
            _pass = value
        End Set
    End Property

End Class